package com.test32_网络编程.udp.client;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UDPClient {

    public static void main(String[] args) throws Exception {
        DatagramSocket client = new DatagramSocket(9999);   // 设置客户端的监听端口
        byte[] data = new byte[1024];   // 准备接收信息
        DatagramPacket packet = new DatagramPacket(data, data.length);
        System.out.println("【UDPClient】客户端等待服务器端发送消息......");
        client.receive(packet);     // 接收消息，如果没有接收到就一直等待
        System.out.println("【UDPClient】接收到消息，消息内容为：" + new String(data, 0, packet.getLength()));
    }
}
